﻿using System;
using System.Data;
using System.Web.UI;
using BLL;
using BLL.Access;
using Entity;
using Web.Class;
//********************************************************************************//
//创建日期：<创建日期，2016-05-16>
//创建作者：<郭登杰>
//功能说明：来函流程公共控件-审批详情 意见
//********************************************************************************//

namespace Web.Controls.LAIHANLC
{
    public partial class UCLHLCSHENPIYIJIANS : UserControl, IUCLHOperate
    {
        #region 变量

        private readonly SpHelper _sphelper = new SpHelper();

        #endregion

        #region 属性

        /// <summary>
        ///     来函类型
        /// </summary>
        public eLaiHanLX LaiHanLX { get; set; }

        #endregion

        /// <summary>
        ///     配置控件
        /// </summary>
        public void InitControl()
        {
            txtYWY.Enabled = false;
            txtZR.Enabled = false;
            txtJSK.Enabled = false;
            txtJCK.Enabled = false;
            txtCZ.Enabled = false;
        }

        /// <summary>
        ///     提交验证
        /// </summary>
        public ValidateRS Validate()
        {
            var rs = new ValidateRS();
            return rs;
        }

        /// <summary>
        ///     清除信息
        /// </summary>
        public void ClearInfo()
        {
        }

        /// <summary>
        ///     加载信息
        /// </summary>
        public void LoadInfo(YS_LH_LAIHANXX laihanxx)
        {
            var drc = _sphelper.P_YS_LHGETSHENPIYJS((int) LaiHanLX, laihanxx.S_LAIHANBH).Tables[0].Rows;
            if (laihanxx.I_LAIHANLX != 1)
            {
                var indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int) laihanxx.I_LAIHANLX, eLaiHanLCBH.业务员);
                txtYWY.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_SHENPIYJ"]) : "";
                imgYWY.ImageUrl = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_CAOZUORQM"]) : "";
                txtYWYDate.Text = indexes.Count > 0
                    ? "审批日期：" + Convert.ToDateTime(drc[indexes[0]]["D_SHURURQ"]).ToString("yyyy/MM/dd")
                    : "审批日期：";
                indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int) laihanxx.I_LAIHANLX, eLaiHanLCBH.主任);
                txtZR.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_SHENPIYJ"]) : "";
                imgZR.ImageUrl = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_CAOZUORQM"]) : "";
                txtZRDate.Text = indexes.Count > 0
                    ? "审批日期：" + Convert.ToDateTime(drc[indexes[0]]["D_SHURURQ"]).ToString("yyyy/MM/dd")
                    : "";
                indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int) laihanxx.I_LAIHANLX, eLaiHanLCBH.节水科);
                txtJSK.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_SHENPIYJ"]) : "";
                imgJSK.ImageUrl = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_CAOZUORQM"]) : "";
                txtJSKDate.Text = indexes.Count > 0
                    ? "审批日期：" + Convert.ToDateTime(drc[indexes[0]]["D_SHURURQ"]).ToString("yyyy/MM/dd")
                    : "";
                indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int) laihanxx.I_LAIHANLX, eLaiHanLCBH.计财科);
                txtJCK.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_SHENPIYJ"]) : "";
                imgJCK.ImageUrl = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_CAOZUORQM"]) : "";
                txtJCKDate.Text = indexes.Count > 0
                    ? "审批日期：" + Convert.ToDateTime(drc[indexes[0]]["D_SHURURQ"]).ToString("yyyy/MM/dd")
                    : "";
                indexes = LaiHanLCTools.GetNeedRowIndexs(drc, (int) laihanxx.I_LAIHANLX, eLaiHanLCBH.处长);
                txtCZ.Text = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_SHENPIYJ"]) : "";
                imgCZ.ImageUrl = indexes.Count > 0 ? Convert.ToString(drc[indexes[0]]["S_CAOZUORQM"]) : "";
                txtCZDate.Text = indexes.Count > 0
                    ? "审批日期：" + Convert.ToDateTime(drc[indexes[0]]["D_SHURURQ"]).ToString("yyyy/MM/dd")
                    : "";
            }
            else
            {
                txtYWY.Text = Convert.ToString(drc[0]["S_YEWUYJY"]);
                txtCZ.Text = Convert.ToString(drc[0]["S_CHUZHANG"]);
                txtJCK.Text = Convert.ToString(drc[0]["S_JICAIKZ"]);
                txtJSK.Text = Convert.ToString(drc[0]["S_JIESHUIKZ"]);
                txtZR.Text = Convert.ToString(drc[0]["S_ZHUREN"]);
                txtYWYDate.Text = "处理日期：" + (!Convert.IsDBNull(drc[0]["D_YWY"]) ? Convert.ToDateTime(drc[0]["D_YWY"]).ToString("yyyy/MM/dd") : "");
                txtZRDate.Text = "复核日期：" + (!Convert.IsDBNull(drc[0]["D_ZR"]) ? Convert.ToDateTime(drc[0]["D_ZR"]).ToString("yyyy/MM/dd") : "");
                txtJSKDate.Text = "审核日期：" + (!Convert.IsDBNull(drc[0]["D_JSK"]) ? Convert.ToDateTime(drc[0]["D_JSK"]).ToString("yyyy/MM/dd") : "");
                txtJCKDate.Text = "复审日期：" + (!Convert.IsDBNull(drc[0]["D_JCK"]) ? Convert.ToDateTime(drc[0]["D_JCK"]).ToString("yyyy/MM/dd") : "");
                txtCZDate.Text = "审批日期：" + (!Convert.IsDBNull(drc[0]["D_CZ"]) ? Convert.ToDateTime(drc[0]["D_CZ"]).ToString("yyyy/MM/dd") : "");
                var liuChengJL = new SqlHelper().GetLaiHanLCJL(laihanxx.S_LAIHANBH).Tables[0];
                if (liuChengJL.Rows.Count > 0)
                {
                    foreach (DataRow row in liuChengJL.Rows)
                    {
                        var liuchengbh = Convert.ToInt32(row["I_LIUCHENGBH"]);
                        switch (liuchengbh)
                        {
                            case 3: imgYWY.ImageUrl = Convert.ToString(row["S_CAOZUORQM"]);
                                //txtYWYDate.Text = "处理日期：" +(!Convert.IsDBNull(row["D_ENDDATE"])? Convert.ToDateTime(row["D_ENDDATE"]).ToString("yyyy/MM/dd"):"");
                                break;
                            case 4: imgZR.ImageUrl = !Convert.IsDBNull(row["D_ENDDATE"]) ?Convert.ToString(row["S_CAOZUORQM"]):"";
                                //txtZRDate.Text = "审批日期：" + (!Convert.IsDBNull(row["D_ENDDATE"]) ? Convert.ToDateTime(row["D_ENDDATE"]).ToString("yyyy/MM/dd") : "");
                                break;
                            case 5: imgJSK.ImageUrl = !Convert.IsDBNull(row["D_ENDDATE"]) ? Convert.ToString(row["S_CAOZUORQM"]) : "";
                                //txtJSKDate.Text = "审批日期：" + (!Convert.IsDBNull(row["D_ENDDATE"]) ? Convert.ToDateTime(row["D_ENDDATE"]).ToString("yyyy/MM/dd") : "");
                                break;
                            case 6: imgJCK.ImageUrl = !Convert.IsDBNull(row["D_ENDDATE"]) ? Convert.ToString(row["S_CAOZUORQM"]) : "";
                                //txtJCKDate.Text = "审批日期：" + (!Convert.IsDBNull(row["D_ENDDATE"]) ? Convert.ToDateTime(row["D_ENDDATE"]).ToString("yyyy/MM/dd") : "");
                                break;
                            case 7: imgCZ.ImageUrl = !Convert.IsDBNull(row["D_ENDDATE"]) ? Convert.ToString(row["S_CAOZUORQM"]) : "";
                                //txtCZDate.Text = "审批日期：" + (!Convert.IsDBNull(row["D_ENDDATE"]) ? Convert.ToDateTime(row["D_ENDDATE"]).ToString("yyyy/MM/dd") : "");
                                break;
                        }
                    }
                }
            }
        }

        /// <summary>
        ///     页面加载事件
        /// </summary>
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                InitControl();
        }
    }
}